// ============================================================================
// Utilities (原子化工具类)
// - 间距、布局、显示、文本、效果等通用工具类
// - 类似 Tailwind CSS 的原子化设计理念
// ============================================================================

@use './variables' as *;

// ------------------------------
// 间距工具类 (Spacing)
// ------------------------------

// 计算间距的函数
@function space($n) { @return $n * 4px; }

// 外边距 (Margin)
.m-0 { margin: 0 !important; }
@for $i from 1 through 10 {
  .m-#{$i} { margin: space($i) !important; }
  .mt-#{$i} { margin-top: space($i) !important; }
  .mr-#{$i} { margin-right: space($i) !important; }
  .mb-#{$i} { margin-bottom: space($i) !important; }
  .ml-#{$i} { margin-left: space($i) !important; }
  .mx-#{$i} { margin-left: space($i) !important; margin-right: space($i) !important; }
  .my-#{$i} { margin-top: space($i) !important; margin-bottom: space($i) !important; }
}
.m-auto { margin: auto !important; }
.mx-auto { margin-left: auto !important; margin-right: auto !important; }
.my-auto { margin-top: auto !important; margin-bottom: auto !important; }

// 内边距 (Padding)
.p-0 { padding: 0 !important; }
@for $i from 1 through 10 {
  .p-#{$i} { padding: space($i) !important; }
  .pt-#{$i} { padding-top: space($i) !important; }
  .pr-#{$i} { padding-right: space($i) !important; }
  .pb-#{$i} { padding-bottom: space($i) !important; }
  .pl-#{$i} { padding-left: space($i) !important; }
  .px-#{$i} { padding-left: space($i) !important; padding-right: space($i) !important; }
  .py-#{$i} { padding-top: space($i) !important; padding-bottom: space($i) !important; }
}

// ------------------------------
// 布局工具类 (Layout & Flexbox)
// ------------------------------

// 显示类型
.d-none { display: none !important; }
.d-block { display: block !important; }
.d-inline { display: inline !important; }
.d-inline-block { display: inline-block !important; }
.d-flex { display: flex !important; }
.d-inline-flex { display: inline-flex !important; }
.d-grid { display: grid !important; }

// Flexbox 方向
.flex-row { flex-direction: row !important; }
.flex-column { flex-direction: column !important; }
.flex-row-reverse { flex-direction: row-reverse !important; }
.flex-column-reverse { flex-direction: column-reverse !important; }

// Flexbox 包装
.flex-wrap { flex-wrap: wrap !important; }
.flex-nowrap { flex-wrap: nowrap !important; }
.flex-wrap-reverse { flex-wrap: wrap-reverse !important; }

// Flexbox 伸缩
.flex-1 { flex: 1 1 0% !important; }
.flex-auto { flex: 1 1 auto !important; }
.flex-initial { flex: 0 1 auto !important; }
.flex-none { flex: none !important; }

// Flexbox 对齐
.justify-start { justify-content: flex-start !important; }
.justify-end { justify-content: flex-end !important; }
.justify-center { justify-content: center !important; }
.justify-between { justify-content: space-between !important; }
.justify-around { justify-content: space-around !important; }
.justify-evenly { justify-content: space-evenly !important; }

.items-start { align-items: flex-start !important; }
.items-end { align-items: flex-end !important; }
.items-center { align-items: center !important; }
.items-baseline { align-items: baseline !important; }
.items-stretch { align-items: stretch !important; }

.content-start { align-content: flex-start !important; }
.content-end { align-content: flex-end !important; }
.content-center { align-content: center !important; }
.content-between { align-content: space-between !important; }
.content-around { align-content: space-around !important; }
.content-evenly { align-content: space-evenly !important; }

// Gap
.gap-0 { gap: 0 !important; }
@for $i from 1 through 10 {
  .gap-#{$i} { gap: space($i) !important; }
  .gap-x-#{$i} { column-gap: space($i) !important; }
  .gap-y-#{$i} { row-gap: space($i) !important; }
}

// ------------------------------
// 文本工具类 (Typography)
// ------------------------------

// 文本对齐
.text-left { text-align: left !important; }
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }
.text-justify { text-align: justify !important; }

// 字体大小
.text-xs { font-size: 12px !important; }
.text-sm { font-size: 13px !important; }
.text-base { font-size: 14px !important; }
.text-md { font-size: 16px !important; }
.text-lg { font-size: 18px !important; }
.text-xl { font-size: 20px !important; }
.text-2xl { font-size: 24px !important; }

// 字体粗细
.font-thin { font-weight: 100 !important; }
.font-light { font-weight: 300 !important; }
.font-normal { font-weight: 400 !important; }
.font-medium { font-weight: 500 !important; }
.font-semibold { font-weight: 600 !important; }
.font-bold { font-weight: 700 !important; }
.font-extrabold { font-weight: 800 !important; }
.font-black { font-weight: 900 !important; }

// 行高
.leading-none { line-height: 1 !important; }
.leading-tight { line-height: 1.25 !important; }
.leading-snug { line-height: 1.375 !important; }
.leading-normal { line-height: 1.5 !important; }
.leading-relaxed { line-height: 1.625 !important; }
.leading-loose { line-height: 2 !important; }

// 文本装饰
.underline { text-decoration: underline !important; }
.line-through { text-decoration: line-through !important; }
.no-underline { text-decoration: none !important; }

// 文本变换
.uppercase { text-transform: uppercase !important; }
.lowercase { text-transform: lowercase !important; }
.capitalize { text-transform: capitalize !important; }
.normal-case { text-transform: none !important; }

// 文本截断
.truncate {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

.text-ellipsis { text-overflow: ellipsis !important; }
.text-clip { text-overflow: clip !important; }

// 多行文本截断
@for $i from 1 through 6 {
  .line-clamp-#{$i} {
    display: -webkit-box !important;
    -webkit-line-clamp: $i !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
  }
}

// 空白处理
.whitespace-normal { white-space: normal !important; }
.whitespace-nowrap { white-space: nowrap !important; }
.whitespace-pre { white-space: pre !important; }
.whitespace-pre-line { white-space: pre-line !important; }
.whitespace-pre-wrap { white-space: pre-wrap !important; }

// ------------------------------
// 颜色工具类 (Colors)
// ------------------------------

// 文本颜色
.text-primary { color: var(--el-color-primary) !important; }
.text-success { color: var(--el-color-success) !important; }
.text-warning { color: var(--el-color-warning) !important; }
.text-danger { color: var(--el-color-danger) !important; }
.text-info { color: var(--el-color-info) !important; }
.text-regular { color: var(--el-text-color-regular) !important; }
.text-secondary { color: var(--el-text-color-secondary) !important; }
.text-placeholder { color: var(--el-text-color-placeholder) !important; }
.text-disabled { color: var(--el-text-color-disabled) !important; }
.text-white { color: #ffffff !important; }
.text-black { color: #000000 !important; }
.text-muted { color: var(--text-muted) !important; }

// 背景颜色
.bg-primary { background-color: var(--el-color-primary) !important; }
.bg-success { background-color: var(--el-color-success) !important; }
.bg-warning { background-color: var(--el-color-warning) !important; }
.bg-danger { background-color: var(--el-color-danger) !important; }
.bg-info { background-color: var(--el-color-info) !important; }
.bg-white { background-color: #ffffff !important; }
.bg-black { background-color: #000000 !important; }
.bg-transparent { background-color: transparent !important; }
.bg-panel { background: var(--bg-panel) !important; }
.bg-hover { background: var(--bg-hover) !important; }
.bg-subtle { background: var(--bg-subtle) !important; }

// ------------------------------
// 边框工具类 (Borders)
// ------------------------------

// 边框
.border { border: 1px solid var(--el-border-color) !important; }
.border-0 { border: 0 !important; }
.border-2 { border: 2px solid var(--el-border-color) !important; }
.border-4 { border: 4px solid var(--el-border-color) !important; }

.border-t { border-top: 1px solid var(--el-border-color) !important; }
.border-r { border-right: 1px solid var(--el-border-color) !important; }
.border-b { border-bottom: 1px solid var(--el-border-color) !important; }
.border-l { border-left: 1px solid var(--el-border-color) !important; }

.border-x { border-left: 1px solid var(--el-border-color) !important; border-right: 1px solid var(--el-border-color) !important; }
.border-y { border-top: 1px solid var(--el-border-color) !important; border-bottom: 1px solid var(--el-border-color) !important; }

.border-none { border: none !important; }
.border-dashed { border-style: dashed !important; }
.border-dotted { border-style: dotted !important; }
.border-solid { border-style: solid !important; }

// 边框颜色
.border-primary { border-color: var(--el-color-primary) !important; }
.border-success { border-color: var(--el-color-success) !important; }
.border-warning { border-color: var(--el-color-warning) !important; }
.border-danger { border-color: var(--el-color-danger) !important; }
.border-info { border-color: var(--el-color-info) !important; }
.border-light { border-color: var(--el-border-color-light) !important; }
.border-lighter { border-color: var(--el-border-color-lighter) !important; }

// 圆角
.rounded-none { border-radius: 0 !important; }
.rounded-sm { border-radius: 2px !important; }
.rounded { border-radius: 4px !important; }
.rounded-md { border-radius: 6px !important; }
.rounded-lg { border-radius: 8px !important; }
.rounded-xl { border-radius: 12px !important; }
.rounded-2xl { border-radius: 16px !important; }
.rounded-3xl { border-radius: 24px !important; }
.rounded-full { border-radius: 9999px !important; }

// 具体圆角
.rounded-t-none { border-top-left-radius: 0 !important; border-top-right-radius: 0 !important; }
.rounded-r-none { border-top-right-radius: 0 !important; border-bottom-right-radius: 0 !important; }
.rounded-b-none { border-bottom-right-radius: 0 !important; border-bottom-left-radius: 0 !important; }
.rounded-l-none { border-top-left-radius: 0 !important; border-bottom-left-radius: 0 !important; }

// ------------------------------
// 尺寸工具类 (Sizing)
// ------------------------------

// 宽度
.w-auto { width: auto !important; }
.w-0 { width: 0 !important; }
.w-full { width: 100% !important; }
.w-screen { width: 100vw !important; }
.w-min { width: min-content !important; }
.w-max { width: max-content !important; }
.w-fit { width: fit-content !important; }

// 高度
.h-auto { height: auto !important; }
.h-0 { height: 0 !important; }
.h-full { height: 100% !important; }
.h-screen { height: 100vh !important; }
.h-min { height: min-content !important; }
.h-max { height: max-content !important; }
.h-fit { height: fit-content !important; }

// 最小宽高
.min-w-0 { min-width: 0 !important; }
.min-w-full { min-width: 100% !important; }
.min-h-0 { min-height: 0 !important; }
.min-h-full { min-height: 100% !important; }
.min-h-screen { min-height: 100vh !important; }

// 最大宽高
.max-w-none { max-width: none !important; }
.max-w-full { max-width: 100% !important; }
.max-w-screen { max-width: 100vw !important; }
.max-h-none { max-height: none !important; }
.max-h-full { max-height: 100% !important; }
.max-h-screen { max-height: 100vh !important; }

// 特定尺寸
@for $i from 1 through 20 {
  .w-#{$i * 4} { width: #{$i * 16}px !important; }
  .h-#{$i * 4} { height: #{$i * 16}px !important; }
}

.max-h-60 { max-height: 15rem !important; }
.max-h-80 { max-height: 20rem !important; }

// ------------------------------
// 定位工具类 (Position)
// ------------------------------

.static { position: static !important; }
.fixed { position: fixed !important; }
.absolute { position: absolute !important; }
.relative { position: relative !important; }
.sticky { position: sticky !important; }

// 定位值
.inset-0 { top: 0; right: 0; bottom: 0; left: 0; }
.top-0 { top: 0 !important; }
.right-0 { right: 0 !important; }
.bottom-0 { bottom: 0 !important; }
.left-0 { left: 0 !important; }

// Z-index
.z-0 { z-index: 0 !important; }
.z-10 { z-index: 10 !important; }
.z-20 { z-index: 20 !important; }
.z-30 { z-index: 30 !important; }
.z-40 { z-index: 40 !important; }
.z-50 { z-index: 50 !important; }
.z-auto { z-index: auto !important; }

// ------------------------------
// 溢出工具类 (Overflow)
// ------------------------------

.overflow-auto { overflow: auto !important; }
.overflow-hidden { overflow: hidden !important; }
.overflow-visible { overflow: visible !important; }
.overflow-scroll { overflow: scroll !important; }

.overflow-x-auto { overflow-x: auto !important; }
.overflow-x-hidden { overflow-x: hidden !important; }
.overflow-x-visible { overflow-x: visible !important; }
.overflow-x-scroll { overflow-x: scroll !important; }

.overflow-y-auto { overflow-y: auto !important; }
.overflow-y-hidden { overflow-y: hidden !important; }
.overflow-y-visible { overflow-y: visible !important; }
.overflow-y-scroll { overflow-y: scroll !important; }

// ------------------------------
// 可见性工具类 (Visibility)
// ------------------------------

.visible { visibility: visible !important; }
.invisible { visibility: hidden !important; }

// 透明度
.opacity-0 { opacity: 0 !important; }
.opacity-25 { opacity: 0.25 !important; }
.opacity-50 { opacity: 0.5 !important; }
.opacity-75 { opacity: 0.75 !important; }
.opacity-100 { opacity: 1 !important; }

// ------------------------------
// 阴影工具类 (Shadows)
// ------------------------------

.shadow-none { box-shadow: none !important; }
.shadow-sm { box-shadow: var(--shadow-sm) !important; }
.shadow { box-shadow: var(--shadow-md) !important; }
.shadow-md { box-shadow: var(--shadow-md) !important; }
.shadow-lg { box-shadow: var(--shadow-lg) !important; }
.shadow-xl { box-shadow: var(--shadow-hover) !important; }
.shadow-hover { box-shadow: var(--shadow-hover) !important; }

// ------------------------------
// 过渡动画工具类 (Transitions)
// ------------------------------

.transition-none { transition: none !important; }
.transition-all { transition: all var(--duration-base) var(--easing-standard) !important; }
.transition-colors { transition: color var(--duration-base) var(--easing-standard), background-color var(--duration-base) var(--easing-standard), border-color var(--duration-base) var(--easing-standard) !important; }
.transition-opacity { transition: opacity var(--duration-base) var(--easing-standard) !important; }
.transition-shadow { transition: box-shadow var(--duration-base) var(--easing-standard) !important; }
.transition-transform { transition: transform var(--duration-base) var(--easing-standard) !important; }

// 动画持续时间
.duration-75 { transition-duration: 75ms !important; }
.duration-100 { transition-duration: 100ms !important; }
.duration-150 { transition-duration: 150ms !important; }
.duration-200 { transition-duration: 200ms !important; }
.duration-300 { transition-duration: 300ms !important; }
.duration-500 { transition-duration: 500ms !important; }
.duration-700 { transition-duration: 700ms !important; }
.duration-1000 { transition-duration: 1000ms !important; }

// ------------------------------
// 光标工具类 (Cursor)
// ------------------------------

.cursor-auto { cursor: auto !important; }
.cursor-default { cursor: default !important; }
.cursor-pointer { cursor: pointer !important; }
.cursor-wait { cursor: wait !important; }
.cursor-text { cursor: text !important; }
.cursor-move { cursor: move !important; }
.cursor-help { cursor: help !important; }
.cursor-not-allowed { cursor: not-allowed !important; }
.cursor-progress { cursor: progress !important; }
.cursor-crosshair { cursor: crosshair !important; }

// ------------------------------
// 用户选择工具类 (User Select)
// ------------------------------

.select-none { user-select: none !important; }
.select-text { user-select: text !important; }
.select-all { user-select: all !important; }
.select-auto { user-select: auto !important; }

// ------------------------------
// 指针事件工具类 (Pointer Events)
// ------------------------------

.pointer-events-none { pointer-events: none !important; }
.pointer-events-auto { pointer-events: auto !important; }

// ------------------------------
// 变形工具类 (Transform)
// ------------------------------

.transform { transform: translateX(var(--tw-translate-x, 0)) translateY(var(--tw-translate-y, 0)) rotate(var(--tw-rotate, 0)) skewX(var(--tw-skew-x, 0)) skewY(var(--tw-skew-y, 0)) scaleX(var(--tw-scale-x, 1)) scaleY(var(--tw-scale-y, 1)) !important; }
.transform-none { transform: none !important; }

// 缩放
.scale-0 { transform: scale(0) !important; }
.scale-50 { transform: scale(.5) !important; }
.scale-75 { transform: scale(.75) !important; }
.scale-90 { transform: scale(.9) !important; }
.scale-95 { transform: scale(.95) !important; }
.scale-100 { transform: scale(1) !important; }
.scale-105 { transform: scale(1.05) !important; }
.scale-110 { transform: scale(1.1) !important; }
.scale-125 { transform: scale(1.25) !important; }
.scale-150 { transform: scale(1.5) !important; }

// 旋转
.rotate-0 { transform: rotate(0deg) !important; }
.rotate-1 { transform: rotate(1deg) !important; }
.rotate-2 { transform: rotate(2deg) !important; }
.rotate-3 { transform: rotate(3deg) !important; }
.rotate-6 { transform: rotate(6deg) !important; }
.rotate-12 { transform: rotate(12deg) !important; }
.rotate-45 { transform: rotate(45deg) !important; }
.rotate-90 { transform: rotate(90deg) !important; }
.rotate-180 { transform: rotate(180deg) !important; }

// 平移
.translate-x-0 { transform: translateX(0) !important; }
.translate-x-1 { transform: translateX(4px) !important; }
.translate-x-2 { transform: translateX(8px) !important; }
.translate-x-4 { transform: translateX(16px) !important; }
.-translate-x-1 { transform: translateX(-4px) !important; }
.-translate-x-2 { transform: translateX(-8px) !important; }
.-translate-x-4 { transform: translateX(-16px) !important; }

.translate-y-0 { transform: translateY(0) !important; }
.translate-y-1 { transform: translateY(4px) !important; }
.translate-y-2 { transform: translateY(8px) !important; }
.translate-y-4 { transform: translateY(16px) !important; }
.-translate-y-1 { transform: translateY(-4px) !important; }
.-translate-y-2 { transform: translateY(-8px) !important; }
.-translate-y-4 { transform: translateY(-16px) !important; }

// ------------------------------
// 伪类状态工具类 (Pseudo-class States)
// ------------------------------

// 悬停状态
.hover\:bg-gray-100:hover { background-color: #f3f4f6 !important; }
.hover\:bg-gray-200:hover { background-color: #e5e7eb !important; }
.hover\:text-primary:hover { color: var(--el-color-primary) !important; }
.hover\:border-primary:hover { border-color: var(--el-color-primary) !important; }
.hover\:shadow-lg:hover { box-shadow: var(--shadow-lg) !important; }
.hover\:scale-105:hover { transform: scale(1.05) !important; }
.hover\:-translate-y-1:hover { transform: translateY(-4px) !important; }

// 焦点状态
.focus\:outline-none:focus { outline: none !important; }
.focus\:ring-2:focus { box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5) !important; }
.focus\:border-primary:focus { border-color: var(--el-color-primary) !important; }

// 激活状态
.active\:scale-95:active { transform: scale(.95) !important; }

// 禁用状态
.disabled\:opacity-50:disabled { opacity: 0.5 !important; }
.disabled\:cursor-not-allowed:disabled { cursor: not-allowed !important; }

// ------------------------------
// 响应式工具类前缀 (Responsive Prefixes)
// ------------------------------

@media (min-width: 640px) {
  .sm\:block { display: block !important; }
  .sm\:hidden { display: none !important; }
  .sm\:flex { display: flex !important; }
  .sm\:grid { display: grid !important; }
}

@media (min-width: 768px) {
  .md\:block { display: block !important; }
  .md\:hidden { display: none !important; }
  .md\:flex { display: flex !important; }
  .md\:grid { display: grid !important; }
  .md\:text-left { text-align: left !important; }
  .md\:text-center { text-align: center !important; }
}

@media (min-width: 1024px) {
  .lg\:block { display: block !important; }
  .lg\:hidden { display: none !important; }
  .lg\:flex { display: flex !important; }
  .lg\:grid { display: grid !important; }
}

@media (min-width: 1280px) {
  .xl\:block { display: block !important; }
  .xl\:hidden { display: none !important; }
  .xl\:flex { display: flex !important; }
  .xl\:grid { display: grid !important; }
}
